// 购物车小仓库
import {reqGetShopCartList,reqDeleteCartById,reqCheckCart} from '@/api'
const state = {
  shopCartList:[]
}

const mutations = {
  SHOPCAR(state,shopCartList){
    state.shopCartList = shopCartList
  }
}
const actions = {
  // 获取购物车列表
  async getShopCartList({commit}){
    let res = await reqGetShopCartList()
   
    if(res.data.length==0){
      res.data[0] = []
    }
    if(res.code==200){
      commit('SHOPCAR',res.data[0].cartInfoList)
    }
  },
  // 删除购物车产品
  async deleteCartById(){
  
    return await reqDeleteCartById(arguments[1])
    
  },
  // 切换商品选中状态 /api/cart/checkCart/{skuID}/{isChecked}
  async checkCart(){
    let {skuId,isChecked} = arguments[1]
    return await reqCheckCart(skuId,isChecked)

  }
}

const getters ={}

export default {
  state,
  mutations,
  actions,
  getters
}